import subprocess
import time
import sys
import re

import math

port = sys.argv[1]
file = sys.argv[2]

assert port is not None
assert file is not None

f = open(file).readlines()

all = f.__len__()
tic = 300/all
print(tic)

if tic < 1:
    tic = 1.5


loop=0
while 1:
    loop+=1
    for _, i in enumerate(f):
        try:
            ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", i)[0]
            time.sleep(tic)
            cmd = "sh se.sh {} {} ".format(ip, port)
            subprocess.Popen(cmd, shell=True)
        except:
            pass

    if loop % 3 == 0:
        subprocess.Popen("sh kill_thread_by_name_pid_1.sh se.sh", shell=True)

